package com.cskaoyan.market.admin.service.impl;

import com.cskaoyan.market.admin.service.ConfigService;
import com.cskaoyan.market.db.domain.MarketSystem;
import com.cskaoyan.market.db.mapper.MarketSystemMapper;
import com.cskaoyan.market.db.vo.MallConfigVo;
import com.cskaoyan.market.util.MarketSystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @NAME: ConfigServiceImpl
 * @DESCRIPTION: TODO
 * @DATE: 2023/5/9 23:48
 * @AUTHOR: 刘超
 */
@SuppressWarnings("DuplicatedCode")
@Service
public class ConfigServiceImpl implements ConfigService {
    @Autowired
    private MarketSystemMapper mapper;
    @Override
    public MallConfigVo queryMall() {

        MallConfigVo mallConfigVo = new MallConfigVo();
        MarketSystem longitude = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_LONGITUDE);
        MarketSystem latitude = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_LATITUDE);
        MarketSystem address = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_ADDRESS);
        MarketSystem phone = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_PHONE);
        MarketSystem qq = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_QQ);
        MarketSystem name = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_NAME);
        mallConfigVo.setMarket_mall_address(address.getKeyValue());
        mallConfigVo.setMarket_mall_latitude(latitude.getKeyValue());
        mallConfigVo.setMarket_mall_longitude(longitude.getKeyValue());
        mallConfigVo.setMarket_mall_phone(phone.getKeyValue());
        mallConfigVo.setMarket_mall_qq(qq.getKeyValue());
        mallConfigVo.setMarket_mall_name(name.getKeyValue());
        
        return mallConfigVo;

    }

    @Override
    public int updateMall(MallConfigVo mallConfigVo) {

        // 得到各个参数的对象
        MarketSystem longitude = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_LONGITUDE);
        MarketSystem latitude = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_LATITUDE);
        MarketSystem address = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_ADDRESS);
        MarketSystem phone = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_PHONE);
        MarketSystem qq = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_QQ);
        MarketSystem name = mapper.selectByPrimaryKey(MarketSystemConstant.MARKET_MALL_NAME);
        // 设置参数的值
        longitude.setKeyValue(mallConfigVo.getMarket_mall_longitude());
        latitude.setKeyValue(mallConfigVo.getMarket_mall_latitude());
        address.setKeyValue(mallConfigVo.getMarket_mall_address());
        phone.setKeyValue(mallConfigVo.getMarket_mall_phone());
        qq.setKeyValue(mallConfigVo.getMarket_mall_qq());
        name.setKeyValue(mallConfigVo.getMarket_mall_name());
        // 替换数据
        mapper.updateByPrimaryKey(address);
        mapper.updateByPrimaryKey(phone);
        mapper.updateByPrimaryKey(qq);
        mapper.updateByPrimaryKey(name);
        mapper.updateByPrimaryKey(latitude);
        mapper.updateByPrimaryKey(longitude);

        
        
        return 0;
    }
}
